package com.mane.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置类
 * @author tarnett
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 往拦截器中注册自定义的拦截器
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(loginInterceptor);
        // 设置拦截的路径(拦截所有请求)
        interceptorRegistration.addPathPatterns("/**");
        // 排除指定的路径（swagger相关请求路径）
        interceptorRegistration.excludePathPatterns( "/swagger-resources/**", "/v3/api-docs/**", "/doc.html");
    }
}